﻿using System;

namespace Transport
{
    public class CartItem : IEquatable<CartItem>
    {

        public int Quantity { get; set; }

        private CartDTO _carInfo;
        public CartDTO CarInfo
        {
            get { return _carInfo; }
            set
            {
                _car = null;
                _carInfo = value;
            }
        }

        private Car _car = null;
        public Car Car
        {
            get
            {

                if (_car == null)
                {
                    _car = new Car(CarInfo);
                }
                return _car;
            }
        }
        public string CarID
        {
            get { return Car.CarInfo.MaXe; }
        }
        public string HieuXe
        {
            get { return Car.CarInfo.HieuXe; }
        }
        public string NgayDi
        {
            get { return String.Format("{0:dd/MM/yy}", Car.CarInfo.TuNgay);}
        }
        public string DiaDiemDon
        {
            get { return Car.CarInfo.DiaDiemDon; }
        }
        public string GioDon
        {
            get { return Car.CarInfo.GioDon.ToString(); }
        }
        public string TenDichVu
        {
            get { return Car.CarInfo.TenDichVu; }
        }
        public decimal TotalPrice
        {
            get { return Car.CarInfo.GiaTien; }
        }

        public CartItem(CartDTO carinfo)
        {
            this.CarInfo = carinfo;
        }

        public bool Equals(CartItem item)
        {
            return item.CarInfo.MaXe == this.CarInfo.MaXe;
        }
        public bool DichVuEquals(CartItem item)
        {
            return item.CarInfo.MaDichVu == this.CarInfo.MaDichVu;
        }
    }
}
